package com.taiyi.renaissancemall.ui.mine.verified;

import android.content.Intent;

import com.taiyi.renaissancemall.Utils.ToastUtils;
import com.taiyi.renaissancemall.Utils.Utils;
import com.taiyi.renaissancemall.base.BasePresent;
import com.taiyi.renaissancemall.base.MyApp;
import com.taiyi.renaissancemall.bean.BaseResultBean;
import com.taiyi.renaissancemall.bean.MyScoresBean;
import com.taiyi.renaissancemall.bean.ResponseBean;
import com.taiyi.renaissancemall.bean.VerifiedBean;
import com.taiyi.renaissancemall.net.BaseUrl;
import com.taiyi.renaissancemall.net.HttpUtils;
import com.taiyi.renaissancemall.net.callbck.JsonCallback;
import com.taiyi.renaissancemall.ui.login.LoginActivity;
import com.taiyi.renaissancemall.ui.mine.scores.MyScoresView;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Response;

public class VerifiedPresent extends BasePresent<VerifiedView> {
    public void getVerified(String identification_name, String identification_number, String front_photo, String reverse_photo) {
        Map<String, String> map = new HashMap<>();
        map.put("identification_name", identification_name);
        map.put("identification_number", identification_number);
        map.put("front_photo", front_photo);
        map.put("reverse_photo", reverse_photo);
        HttpUtils.postRequest(BaseUrl.USER_AUTH, this, map, new JsonCallback<BaseResultBean<VerifiedBean>>() {
            @Override
            public BaseResultBean<VerifiedBean> convertResponse(Response response) throws Throwable {
                return super.convertResponse(response);
            }

            @Override
            public void onSuccess(com.lzy.okgo.model.Response<BaseResultBean<VerifiedBean>> response) {
                super.onSuccess(response);
                if (response.body().code == 0) {
                    view.VerifiedSuccess(response.body().msg_cn);
                } else if(response.body().code == -1){
                    ToastUtils.showShortToast(response.body().msg_cn);
                    Utils.getSpUtils().remove("token");
                    Intent intent = new Intent(MyApp.getInstance(), LoginActivity.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    MyApp.getInstance().startActivity(intent);
                }else {
                    view.VerifiedFailure(response.body().msg_cn);
                }
            }

            @Override
            public void onError(com.lzy.okgo.model.Response<BaseResultBean<VerifiedBean>> response) {
                super.onError(response);
            }
        });
    }

}
